package tinybase.ix;

import tinybase.basic.RC;
import tinybase.basic.RedBase;

public class IX_Errors {
	
	//
	// Error table
	//
	static String[] IX_WarnMsg = {
		"invalid index number",
		"invalid comparison operator",
		"invalid attribute parameters",
		"null pointer",
		"scan open",
		"scan closed",
		"file closed",
		"entry not found",
		"entry already exists",
		"end of file"
	};

	static String[] IX_ErrorMsg = {
	  "no memory"
	};

	// 
	// IX_PrintError
	//
	// Desc: Send a message corresponding to a IX return code to cerr
	// In:   rc - return code for which a message is desired
	//
	public static void printErrors(RC rc) {
		// Check the return code is within proper limits
		if (rc.getValue() >= RedBase.START_IX_WARN &&
				rc.getValue() <= RC.IX_LASTWARN.getValue())
			// Print warning
			System.err.println("IX warning: " + 
					IX_WarnMsg[rc.getValue() - RedBase.START_IX_WARN]);
		// Error codes are negative, so invert everything
		else if ((0-rc.getValue()) >= (0-RedBase.START_IX_ERR) &&
				(0-rc.getValue()) <= (0-RC.IX_LASTERROR.getValue()))
			// Print Errors
			System.err.println("IX error: " + IX_ErrorMsg[0-rc.getValue()
			        + RedBase.START_IX_ERR]);
		else if (rc.getValue() == 0)
			System.err.println("IX_PrintError called with return code of 0");
		else
			System.err.println("IX error: " + rc.getValue() + 
					" is out of bounds");
	}
	
}
